package com.mzj.saas.mservice.propertybill.controller;

import com.mzj.saas.commons.ApiData;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.bill.vo.BillSearchRequestVO;
import com.mzj.saas.mservice.bill.vo.CreateBillRequestParamVO;
import com.mzj.saas.mservice.bill.vo.EditBillRequestVO;
import com.mzj.saas.mservice.bill.vo.NewProjectVO;
import com.mzj.saas.mservice.house.vo.HouseVO;
import com.mzj.saas.mservice.property.entity.HouseRemainingRecord;
import com.mzj.saas.mservice.propertybill.service.NewPropertyBillService;
import com.mzj.saas.mservice.propertybill.service.PayEstateBillService;
import com.mzj.saas.mservice.propertybill.vo.IncomeAndExpenditureVO;
import com.mzj.saas.mservice.propertybill.vo.UrgingPaymentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 非公租房-缴费管理
 */
@Controller
@RequestMapping("/payEstate")
@Api(tags = "缴费管理")
public class PayEstateBillController {
    @Autowired
    private PayEstateBillService payEstateBillService;
    @Autowired
    private NewPropertyBillService newPropertyBillService;

    /**
     * 账单列表-列表信息显示
     *
     * @param accessToken
     * @param pageNumber
     * @param pageSize
     * @param type        0全部账单 1未审核账单 2未缴费账单 3 已缴费账单 4未通过账单
     * @param filter
     * @return
     */
    @GetMapping(value = "billListShow")
    @ResponseBody
    public ResultBean<Object> billListShow(@RequestHeader String accessToken,
                                           @RequestParam(defaultValue = "0") Integer pageNumber,
                                           @RequestParam(defaultValue = "10") Integer pageSize,
                                           @RequestParam(name = "type", defaultValue = "0") Integer type,
                                           @RequestParam(name = "collectionOrg") Long collectionOrg,
                                           BillSearchRequestVO filter) {
        return payEstateBillService.billListShow(accessToken, pageNumber, pageSize, type, collectionOrg, filter);
    }

    /**
     * 账单列表-编辑账单
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @PostMapping(value = "editBill")
    @ResponseBody
    public ResultBean<Object> editBill(@RequestHeader String accessToken, @RequestBody EditBillRequestVO vo) {
        return payEstateBillService.editBill(accessToken, vo);
    }

    /**
     * 账单列表-计算账单金额
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @PostMapping(value = "countBill")
    @ResponseBody
    public ResultBean<Double> countBill(@RequestHeader String accessToken, @RequestBody EditBillRequestVO vo) {
        return payEstateBillService.countBill(accessToken, vo);
    }
    /**
     * 账单列表-审核
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @PostMapping(value = "examineBill")
    @ResponseBody
    public ResultBean<Object> examineBill(@RequestHeader String accessToken, @RequestBody EditBillRequestVO vo) {
        return payEstateBillService.examineBill(accessToken, vo);
    }

    /**
     * 账单列表-设置
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @PostMapping(value = "setupBill")
    @ResponseBody
    public ResultBean<Object> setupBill(@RequestHeader String accessToken, @RequestBody EditBillRequestVO vo) {
        return payEstateBillService.setupBill(accessToken, vo);
    }

    /*
     *租金列表-列表信息展示
     * type 0全部账单  1未缴费账单  2 已缴费账单
     */
    @GetMapping(value = "rentList")
    @ResponseBody
    public ResultBean<Object> rentList(@RequestHeader String accessToken,
                                       @RequestParam(defaultValue = "0") Integer pageNumber,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       @RequestParam(name = "type", defaultValue = "0") Integer type,
                                       BillSearchRequestVO filter) {
        return payEstateBillService.rentList(accessToken, pageNumber, pageSize, type, filter);
    }

    /**
     * 账单生成-列表显示
     *
     * @param accessToken
     * @param pageNumber
     * @param pageSize
     * @param id          账单id
     * @param communityId 小区id
     * @return
     */
    @GetMapping(value = "createBillList")
    @ResponseBody
    @ApiOperation("账单生成列表")
    public ResultBean<Object> createBillList(@RequestHeader String accessToken,
                                             @RequestParam(defaultValue = "0") Integer pageNumber,
                                             @RequestParam(defaultValue = "10") Integer pageSize,
                                             @RequestParam(name = "id", required = false) String id,
                                             @RequestParam(name = "communityId", required = false) String communityId,
                                             @RequestParam(name = "collectionOrg") Integer orgId,
                                             @ApiParam(name = "name", value = "账单记录名") @RequestParam(required = false) String name) {
        return payEstateBillService.createBillList(accessToken, pageNumber, pageSize, id, communityId, orgId, name);
    }

    /**
     * 账单生成
     *
     * @param accessToken
     * @param createBillRequestParamVO
     * @return
     */
    @PostMapping(value = "createBill")
    @ResponseBody
    @ApiOperation("账单生成")
    public ResultBean<Object> createBill(@RequestHeader String accessToken,
                                         @RequestBody CreateBillRequestParamVO createBillRequestParamVO) {
        return newPropertyBillService.createBill(accessToken, createBillRequestParamVO);
    }

    /*
     *账单生成-编辑账单
     */
    @PutMapping(value = "updateBill")
    @ResponseBody
    public ResultBean<Object> updateBill(@RequestHeader String accessToken, @RequestBody CreateBillRequestParamVO createBillRequestParamVO) {
        return newPropertyBillService.updateBill(accessToken, createBillRequestParamVO);
    }

    /*
     *账单生成-删除账单
     */
    @DeleteMapping(value = "deleteBill")
    @ResponseBody
    public ResultBean<Object> deleteBill(@RequestHeader String accessToken, String id) {

        return newPropertyBillService.deleteBill(accessToken, id);
    }

    /*
     *账单生成-账单详情
     */
    @GetMapping(value = "billInfo")
    @ResponseBody
    public ResultBean<Object> billInfo(@RequestHeader String accessToken, String id) {

        return newPropertyBillService.billInfo(accessToken, id);
    }

    /**
     * 收费项目列表
     *
     * @param accessToken
     * @param pageNumber
     * @param pageSize
     * @param vo          收费项目VO
     * @return
     */
    @GetMapping(value = "projectList")
    @ResponseBody
    public ResultBean<ApiData<NewProjectVO>> projectList(@RequestHeader String accessToken,
                                                         @RequestParam(defaultValue = "0") Integer pageNumber,
                                                         @RequestParam(defaultValue = "10") Integer pageSize,
                                                         NewProjectVO vo) {
        return newPropertyBillService.projectList(accessToken, pageNumber, pageSize, vo);
    }

    /**
     * 收费项目-添加更新
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @PostMapping(value = "projectSave")
    @ResponseBody
    public ResultBean<Object> projectSave(@RequestHeader String accessToken, @RequestBody NewProjectVO vo) {

        return newPropertyBillService.projectSave(accessToken, vo);
    }

    /**
     * 收费项目-删除
     *
     * @param accessToken
     * @param id
     * @return
     */
    @DeleteMapping("/projectDelete")
    @ResponseBody
    public ResultBean<Object> projectDelete(@RequestHeader String accessToken, String id) {

        return newPropertyBillService.projectDelete(accessToken, id);
    }

    /**
     * 查询收费项目
     *
     * @param accessToken
     * @return
     */
    @GetMapping("/findByProjectList")
    @ResponseBody
    public ResultBean<Object> findByProjectList(@RequestHeader String accessToken, NewProjectVO newProjectVO ) {

        return newPropertyBillService.findByProjectList(accessToken, newProjectVO);
    }

    /*
     * 查询账单范围下的房源数据
     * scope: 账单范围选择[ 1物业、2小区、3楼栋、4单元、5房号]
     * chargeType :收费项目(1水费 2电费 3物业费 4宽带费 5电视费 6煤气费 7暖气费 8租金 9押金)
     */
    @GetMapping("/findByHouseInfo")
    @ResponseBody
    public ResultBean<Object> findByHouseInfo(@RequestHeader String accessToken,
                                              @RequestParam(defaultValue = "0") Integer pageNumber,
                                              @RequestParam(defaultValue = "10") Integer pageSize,
                                              Integer scope, Integer chargeType, String communityId, String buildingNum, String unitId, String roomNumber) {

        return newPropertyBillService.findByHouseInfo(accessToken, pageNumber, pageSize, scope, chargeType, communityId, buildingNum, unitId, roomNumber);
    }

    /**
     * 收支登记
     *
     * @param accessToken
     * @param pageNumber
     * @param pageSize
     * @param filter      条件查询
     * @return
     */
    @GetMapping(value = "incomeAndExpenditure")
    @ResponseBody
    public ResultBean<ApiData<IncomeAndExpenditureVO>> incomeAndExpenditure(@RequestHeader String accessToken,
                                                                            @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                            @RequestParam(defaultValue = "10") Integer pageSize,
                                                                            BillSearchRequestVO filter) {
        return payEstateBillService.incomeAndExpenditure(accessToken, pageNumber, pageSize, filter);
    }

    /**
     * 收款单位列表
     *
     * @param accessToken
     * @return
     */
    @GetMapping("/findCollectionOrg")
    @ResponseBody
    public ResultBean<Object> findCollectionOrg(@RequestHeader String accessToken) {
        return newPropertyBillService.findCollectionOrg(accessToken);
    }


    /**
     * 获得账单范围 产权单位 物业 数据
     *
     * @param accessToken
     * @return scope: 账单范围选择[ 1物业、2小区、3楼栋、4单元、5房号,6机构，7产权单位 8 物业]
     */
    @GetMapping("/billingRange")
    @ResponseBody
    public ResultBean<Object> billingRange(@RequestHeader String accessToken,
                                           Integer scope) {
        return newPropertyBillService.billingRange(accessToken, scope);
    }


    /**
     * 获得账单范围机构数据
     *
     * @param accessToken
     * @return
     */
    @GetMapping("/companyName")
    @ResponseBody
    public ResultBean<Object> companyName(@RequestHeader String accessToken) {
        return newPropertyBillService.companyName(accessToken);
    }


    /*
     * 查询账单范围下的房源数据
     * scope: 账单范围选择[ 1物业、2小区、3楼栋、4单元、5房号,6机构，7产权单位 8 物业]
     * chargeType :收费项目(1水费 2电费 3物业费 4宽带费 5电视费 6煤气费 7暖气费 8租金 9押金)
     */
    @GetMapping("/houseInfo")
    @ResponseBody
    public ResultBean<Object> houseInfo(@RequestHeader String accessToken,
                                        @RequestParam(defaultValue = "0") Integer pageNumber,
                                        @RequestParam(defaultValue = "10") Integer pageSize,
                                        Integer scope, Integer chargeType, String communityId, String buildingNum, String unitId, String roomNumber, Long orgId, String companyName) {

        return newPropertyBillService.houseInfo(accessToken, pageNumber, pageSize, scope, chargeType, communityId, buildingNum, unitId, roomNumber, orgId, companyName);
    }


    /**
     * 账单列表-催缴费
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @PostMapping("/urgingPayment")
    @ResponseBody
    public ResultBean<Object> urgingPayment(@RequestHeader String accessToken, @RequestBody UrgingPaymentVo vo) {
        return newPropertyBillService.urgingPayment(accessToken, vo);
    }

    /**
     * 账单生成-立即生成
     * @param accessToken
     * @param ruleId
     * @author qixi
     * @date 2023年3月6日
     */
    @GetMapping("/generateBill")
    @ResponseBody
    @ApiOperation("账单立即生成")
    public ResultBean<Object> generateBill(@RequestHeader String accessToken,
                                           @ApiParam(value = "账单规则id", required = true) @RequestParam String ruleId) {
        return newPropertyBillService.generateBill(accessToken, ruleId);
    }


    /**
     * 充值明细
     */
    @GetMapping("/recharge")
    @ResponseBody
    public ResultBean<ApiData<HouseVO>> recharge(@RequestHeader String accessToken,
                                                 @RequestParam(defaultValue = "0") Integer pageNumber,
                                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                                 HouseVO vo) {
        return payEstateBillService.recharge(accessToken, pageNumber, pageSize, vo);
    }

    /**
     * 费用详情
     */
    @GetMapping("/feeDetails")
    @ResponseBody
    public ResultBean<ApiData<HouseRemainingRecord>> feeDetails(@RequestHeader String accessToken,
                                                                @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                @RequestParam(defaultValue = "10") Integer pageSize,
                                                                HouseRemainingRecord houseRemainingRecord) {
        return payEstateBillService.feeDetails(accessToken, pageNumber, pageSize, houseRemainingRecord);
    }


    /**
     * 线下退款
     */
    @PostMapping("/returnPremium")
    @ResponseBody
    public ResultBean<Object> returnPremium(@RequestHeader String accessToken, @RequestBody HouseRemainingRecord houseRemainingRecord) {
        return payEstateBillService.returnPremium(accessToken, houseRemainingRecord);
    }

}
